<?php
/**
 * Created by PhpStorm.
 * User: 69548
 * Date: 2018/8/15
 * Time: 11:01
 */

namespace app\admin\controller;


use app\admin\model\Member as M;
use app\admin\model\Order as O;

class Personal extends User
{


    public function index(){
      $id=  input('id');
      $m=new M;
      $od=new O();
        if (empty($id)) return '参数错误请重试';
        else
       $member=$m->where('member_id',$id)->find();
        $count       =$od
            ->where('member_id',$member['member_id'])
            ->where('isdelete',0)
            ->count();
        $page=input('page');
$b['a.member_id']=$member['member_id'];

        $order=$od
            ->alias('a')
            ->where($b)
            ->join('goods g','a.goods_id=g.goods_id')
            ->field('a.*,g.goods_name')
            ->order('a.creattime desc')
            ->select();
$tongji=[];
        $map['order_status'] =  array(['=',3],['=',4],['=',2],'or');
        $map1['finished_condition'] = 0;
        $map1['isdelete'] =0;
        $map1['order_status'] =  array(['=',1],['=',5],['=',6],['=',7],['=',9],'or');//['=',7]

        $count=$od->where('member_id',$member['member_id'])->where($map)->count('member_id');//已完成订单统计
        $qian=$od->where('member_id',$member['member_id'])->where($map)->sum('fold_money'); //价格计算

        $count1=$od->where('member_id',$member['member_id'])->where($map1)->count('member_id');//未完成订单统计
        $qian1=$od->where('member_id',$member['member_id'])->where($map1)->sum('fold_money');//价格计算

        $count2=$od->where('member_id',$member['member_id'])->where('order_status',8)->count('member_id');//退款订单统计
        $qian2=$od->where('member_id',$member['member_id'])->where('order_status',8)->sum('fold_money');//价格计算
        $count4=$od->where('member_id',$member['member_id'])->where('isdelete',1)->count('member_id');//退款订单统计

        $tongji['yiwancheng']=$count;
        $tongji['yiwanchengq']=$qian;
        $tongji['weiwancheng']=$count1;
        $tongji['weiwanchengq']=$qian1;
        $tongji['tuikuan']=$count2;
        $tongji['tuikuanq']=$qian2;
        $tongji['isdelete']=$count4;


        $tixian1=db('putforward')->where('member_id',$member['member_id'])->order('id desc')->select();
      $data=[];
        foreach ($tixian1 as $v){
            $data[]=[
              'money'=>$v['money'],
              'time'=>!empty($v['time'])?date('Y-m-d H:i:s',$v['time']):'-',
              'state'=>$v['state'],
              'tishi'=>'提现',
              'order_name'=>"-",
              'tis'=>1,
            ];

        }
        $tixian2=db('distributiondetails')->where('member_id',$member['member_id'])->order('id desc')->select();
        foreach ($tixian2 as $v){
            $order_name = isset($v['order_name']) ? $v['order_name'] : "-";
            $time = isset($v['consumption_time']) ? date("Y-m-d H:i:s",$v['consumption_time']) : "-";
            $data[]=[
                'money'=>$v['money'],
                'time'=>$time,
                'state'=>6,
                'tishi'=>'获得佣金',
                'order_name'=>$order_name,
                'tis'=>2,
            ];

        }
        $this->assign('tongji',$tongji);
        $this->assign('member',$member);
        $this->assign('order',$order);
        $this->assign('tixian',$data);


//            return view();


//    dump($order);


        return $this->fetch();
    }




}